<template>
  <div v-if="isActive" class="tab-pane">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'TabPane',
  props: {
    title: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      isActive: false,
    };
  },
  methods: {
    updateActiveStatus(index) {
      this.isActive = this.$parent.$data.activeTab === index;
    },
  },
  mounted() {
    const index = this.$parent.$children.findIndex((child) => child === this);
    this.$parent.$on('tab-change', this.updateActiveStatus);
    this.updateActiveStatus(index);
  },
  beforeDestroy() {
    this.$parent.$off('tab-change', this.updateActiveStatus);
  },
};
</script>

<style scoped>
.tab-pane {
  padding: 20px;
}
</style>
